package lc.q51_100;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述
 *
 * @author lgb
 * @date 2020/12/19
 **/
public class Q71 {

    public String simplifyPath(String path) {
        String[] arr = path.split("/");
        List<String> paths = new ArrayList<>();
        for (String s : arr) {
            if (s.equals(".") || s.equals("")) {
                continue;
            }
            if (s.equals("..") ) {
                if (paths.size() > 0) {
                    paths.remove(paths.size() -1);
                }
                continue;
            }
            paths.add(s);
        }
        StringBuilder sb = new StringBuilder();
        for (String s : paths) {
            sb.append("/");
            sb.append(s);
        }
        if (sb.length() == 0) {
            sb.append("/");
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(new Q71().simplifyPath("/a//b////c/d//././/.."));
    }

}
